home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Extensions / Imaging / PIL / ImageChops.py < prev    next >
Encoding:
Text File  |  2000-06-23  |  3.1 KB  |  130 lines

  1. #
  2. # The Python Imaging Library.
  3. # $Id: ImageChops.py,v 1.1.1.1 1998/08/18 13:07:57 sjoerd Exp $
  4. #
  5. # standard channel operations
  6. #
  7. # History:
  8. #    96-03-24 fl    Created
  9. #    96-08-13 fl    Added logical operations (for "1" images)
  10. #
  11. # Copyright (c) Secret Labs AB 1997.
  12. # Copyright (c) Fredrik Lundh 1996.
  13. #
  14. # See the README file for information on usage and redistribution.
  15. #
  16.  
  17. import Image
  18.  
  19. def constant(image, value):
  20.     "Fill a channel with a given grey level"
  21.  
  22.     return Image.new("L", image.size, value)
  23.  
  24. def duplicate(image):
  25.     "Create a copy of a channel"
  26.  
  27.     return image.copy()
  28.  
  29. def invert(image):
  30.     "Invert a channel"
  31.  
  32.     image.load()
  33.     return Image.Image()._makeself(image.im.chop_invert())
  34.  
  35. def lighter(image1, image2):
  36.     "Select the lighter pixels from each image"
  37.  
  38.     image1.load()
  39.     image2.load()
  40.     return Image.Image()._makeself(image1.im.chop_lighter(image2.im))
  41.  
  42. def darker(image1, image2):
  43.     "Select the darker pixels from each image"
  44.  
  45.     image1.load()
  46.     image2.load()
  47.     return Image.Image()._makeself(image1.im.chop_darker(image2.im))
  48.  
  49. def difference(image1, image2):
  50.     "Subtract one image from another"
  51.  
  52.     image1.load()
  53.     image2.load()
  54.     return Image.Image()._makeself(image1.im.chop_difference(image2.im))
  55.  
  56. def multiply(image1, image2):
  57.     "Superimpose two positive images"
  58.     
  59.     image1.load()
  60.     image2.load()
  61.     return Image.Image()._makeself(image1.im.chop_multiply(image2.im))
  62.  
  63. def screen(image1, image2):
  64.     "Superimpose two negative images"
  65.  
  66.     image1.load()
  67.     image2.load()
  68.     return Image.Image()._makeself(image1.im.chop_screen(image2.im))
  69.  
  70. def add(image1, image2, scale = 1.0, offset = 0):
  71.     "Add two images"
  72.  
  73.     image1.load()
  74.     image2.load()
  75.     return Image.Image()._makeself(image1.im.chop_add(image2.im,
  76.                               scale, offset))
  77.  
  78. def subtract(image1, image2, scale = 1.0, offset = 0):
  79.     "Subtract two images"
  80.  
  81.     image1.load()
  82.     image2.load()
  83.     return Image.Image()._makeself(image1.im.chop_subtract(image2.im,
  84.                                scale, offset))
  85.  
  86. def add_modulo(image1, image2):
  87.     "Add two images without clipping"
  88.  
  89.     image1.load()
  90.     image2.load()
  91.     return Image.Image()._makeself(image1.im.chop_add_modulo(image2.im))
  92.  
  93. def subtract_modulo(image1, image2):
  94.     "Subtract two images without clipping"
  95.  
  96.     image1.load()
  97.     image2.load()
  98.     return Image.Image()._makeself(image1.im.chop_subtract_modulo(image2.im))
  99.  
  100. def logical_and(image1, image2):
  101.     "Logical and between two images"
  102.  
  103.     image1.load()
  104.     image2.load()
  105.     return Image.Image()._makeself(image1.im.chop_and(image2.im))
  106.  
  107. def logical_or(image1, image2):
  108.     "Logical or between two images"
  109.  
  110.     image1.load()
  111.     image2.load()
  112.     return Image.Image()._makeself(image1.im.chop_or(image2.im))
  113.  
  114. def logical_xor(image1, image2):
  115.     "Logical xor between two images"
  116.  
  117.     image1.load()
  118.     image2.load()
  119.     return Image.Image()._makeself(image1.im.chop_xor(image2.im))
  120.  
  121. def blend(image1, image2, alpha):
  122.     "Blend two images using a constant transparency weight"
  123.  
  124.     return Image.blend(image1, image2, alpha)
  125.  
  126. def composite(image1, image2, mask):
  127.     "Create composite image by blending images using a transparency mask"
  128.  
  129.     return Image.composite(image1, image2, mask)
  130.